package com.indusfo.spc.controller;

import com.alibaba.fastjson.JSON;
import com.indusfo.spc.aspect.SystemControllerLog;
import com.indusfo.spc.pojo.Role;
import com.indusfo.spc.service.RoleService;
import com.indusfo.spc.vo.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 角色信息表后台业务接口  
 * @author 贺闻博
 * 
 *   2018年11月29日
 */
@Controller
@RequestMapping("/service/role")
public class RoleController {
     
	@Autowired
	private RoleService roleService;
	/**
	 * 查询角色信息
	 * @param role
	 * @return
	 */
	@RequestMapping(value="selectRoleS")
	@ResponseBody
	public JSONObject selectRoleS(Role role){
		JSONObject listRole = roleService.selectRoleS(role);
	  	return listRole;
	}

	
	/**
	 * 新增角色信息
	 * @param role
	 * @return
	 */
	@RequestMapping(value = "insertRole")
	@ResponseBody
	public JSONObject insertRole(@RequestBody Role role){
	  try {
      return roleService.insertRole(role);
    }catch (Exception e){
	    e.printStackTrace();
      return JSONObject.build(JSONObject.ERROR, e.getMessage(), null);
    }
	}

  /**
   * 停用启用用戶接口
   * @Title: UserController
   * @param roleIds
   * @param dataState
   * @return
   */
  @RequestMapping(value = "/definesRole")
  @SystemControllerLog(description="停用启用用户信息")
  @ResponseBody
  public JSONObject definesRole(Integer[] roleIds, Integer dataState) {
    String msg  = roleService.deleteRole(roleIds, dataState);
   return JSONObject.oK(msg);
  }

  /**
   * 删除角色信息
   * @param roleIds
   * @return
   */
  @RequestMapping(value="deleteRole")
  @ResponseBody
  public JSONObject deleteRole(Integer[] roleIds){
    Integer data = 2;
    String msg = roleService.deleteRole(roleIds, data);
    return JSONObject.oK(msg);
  }

  /**
   * 修改角色信息
   * @return
   */
  @RequestMapping(value = "updateRole")
  @ResponseBody
  public JSONObject updateRole(@RequestBody Role role){
    try {
      return roleService.updateRole(role);
    }catch (Exception e){
      e.printStackTrace();
      return JSONObject.build(JSONObject.ERROR, e.getMessage(), null);
    }
  }

}
